package cn.xaut.XAUT迎春杯预热;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class demoL {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int m = input.nextInt();

        List<Integer> list = new LinkedList<>();
        
        // i 的下一个数为 a[i]
        int[] a = new int[n + 1];
        
        // i 是否为队首元素
        boolean[] b = new boolean[n + 1];
        Arrays.fill(b, true);
        
        for (int i = 1; i <= n; i++) {
            int x = input.nextInt();
            int y = input.nextInt();
            a[x] = y;
            b[y] = false;
        }

        // 寻找队首元素
        for (int i = 1; i <= n; i++) {
            if (b[i]) {
                list.add(i);
                int t = a[i];
                while (t != 0) {
                    list.add(t);
                    t = a[t];
                }
                break;
            }
        }

        for (int i = 0; i < m; i++) {
            int x = input.nextInt();
            int y = input.nextInt();
            int index = list.indexOf(x);
            list.add(index + 1, y);
        }
        for (int x : list)
            System.out.println(x);
    }
}
